#ifndef STRINGTOKENIZER_H
#define STRINGTOKENIZER_H
#include <string>
#include <queue>

//! Class for tokenizing strings
class StringTokenizer{
public:
	//! default constructor
	inline StringTokenizer() : m_returnDelimeters(false), m_stringLength(0), m_string(""), m_delimeters("") {}
	//! creates a tokenizer for the string str, using the delimeters delims. You could also treat delimeters as tokens.
	/** By default delims is the whitespace character and return delimeters is false.*/
	explicit StringTokenizer(const std::string str, const std::string delims = " ", bool returnDelimeters = false);

	//! checks if the tokenizer has tokens to tokenize.
	bool hasMoreTokens();
	//! returns the next token;
	/** returns an empty string if there are no tokens left.*/
	std::string nexToken();

	//! change the string the tokenizer is currently working on
	inline void setString(const std::string str) { m_string = str; }
	//! change the delimeters used by the tokenizer.
	/** you can change your delimeters while tokenizing.*/
	inline void setDelimeters(const std::string delims) { m_delimeters = delims; }
	//! if set to true, the tokenizer will treat delimeters as tokens, else otherwise.
	inline void setDelimitersAsTokens(bool b) { m_returnDelimeters = b; }
private:
	//! current string the tokenizer is working on
	std::string m_string;
	//! the delimeters used by the tokenizer
	std::string m_delimeters;
	//! determines how the delimeters are handled by the tokenizer
	bool m_returnDelimeters;
	
	//! length of m_string
	int m_stringLength;

protected:
	// Tokenizer Helpers
	
	//! checks if the ch is a delimeter
	bool isDelimeter(const char ch);
	//! converts a queue of characters to a string	
	std::string toString(std::queue<char> &st);
};

#endif // STRINGTOKENIZER_H